package com.youhong.teethcare.settingpage;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.youhong.teethcare.R;
import com.youhong.teethcare.StartPageActivity;
import com.youhong.teethcare.services.Common;
import com.youhong.teethcare.utils.DBHelper;


public class LogOutActivity extends Activity implements View.OnClickListener {
    /**
     * Views
     **/
    TextView tv_confirm;
    TextView tv_cancel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_log_out);
    }

    boolean isInitialized = false;

    @Override
    protected void onStart() {
        // TODO Auto-generated method stub
        super.onStart();

        if (!isInitialized) {

            getViews();
            adjustViewsLayoutParams();
            initializeVariables();
            isInitialized = !isInitialized;
        }
    }

    private void initializeVariables() {

    }

    private void adjustViewsLayoutParams() {

        int screen_width = super.getWindowManager().getDefaultDisplay().getWidth();
        int screen_height = super.getWindowManager().getDefaultDisplay().getHeight();

        Window window = super.getWindow();
        WindowManager.LayoutParams window_layout = window.getAttributes();

        window_layout.width = (int) (screen_width * 0.95);
        window_layout.height = (int) (screen_height * 0.25);
        window_layout.verticalMargin = 0.35f;
        
        // Window's background is transparent
        window.setBackgroundDrawable(getResources().getDrawable(R.color.transparent));

    }


    private void getViews() {

        tv_confirm = (TextView) this.findViewById(R.id.logOut_tv_confirm);
        tv_confirm.setOnClickListener(this);

        tv_cancel = (TextView) this.findViewById(R.id.logOut_tv_cancel);
        tv_cancel.setOnClickListener(this);
    }


    public void onClick(View v) {

        if (v == tv_confirm) {

          //  DBHelper.getDbHelper(this).deleteAllDrinkRecord(CommonData.userInfo.getToken());
            Common.userInfo.setToken("");
            Common.userInfo.SyncToLocal(this);

            Intent intent = new Intent(LogOutActivity.this, StartPageActivity.class);
            setResult(RESULT_OK);
            startActivity(intent);
            finish();


        } else if (v == tv_cancel) {

            this.finish();

        }

    }
}
